#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=998244353;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

	int n,q;
	cin >> n >> q;
	vector <int> a[n+2];
	for(int i=0;i<n;i++)
	{
		int sum;
		cin >> sum;
		while(sum--)
		{
			int x;
			cin >> x;
			a[i].push_back(x);
		}
	}
	while(q--)
	{
		int i,j;
		cin >> i >> j;
		cout << a[i-1][j-1] << endl;
	}
    return 0;
}
